package at.hockey.ticker;

import java.util.ListIterator;

import at.hockey.ticker.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MatchOverviewUI extends LinearLayout {

	private HockeyTickerUI mHTUI;
	private LinearLayout mLL;
	
	public MatchOverviewUI(HockeyTickerUI root) {
		super(root);

		this.mHTUI = root;

		//instantiate xml layout
		LayoutInflater inflater = (LayoutInflater) this.mHTUI.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.matchoverview, this);
		
		this.mLL = (LinearLayout) this.findViewById(R.id.mo_details_ll);

		String lastDateTime = "";
		MatchDetails md = null;
		ListIterator<MatchDetails> itr = MatchOverview.getInstance().getMatchDetails().listIterator();
	    while(itr.hasNext()){
	    	
	    	md = itr.next();
	    	
	    	if(lastDateTime != md.getDateTime()){
	    		this.addDateTimeDivider(md.getDateTime());
	    	}
	    	lastDateTime = md.getDateTime();
	    	
	    	this.mLL.addView(new MatchOverviewEntryUI(this.mHTUI, md));
	    }
	}
	
    private void addDateTimeDivider(String datetime){

		//instantiate xml layout
    	LayoutInflater inflater = (LayoutInflater) this.mHTUI.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		TextView tv = (TextView) inflater.inflate(R.layout.divider, null);
    	
		tv.setText(datetime);

    	this.mLL.addView(tv);
    }

}
